package com.pirestupppai.adapter;

import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;

import com.pirestupppai.R;
import com.pirestupppai.base.BaseAdapter;
import com.pirestupppai.base.BaseViewHolder;
import com.pirestupppai.bean.MissionData;
import com.pirestupppai.utils.ImageLoadUtil;
import com.pirestupppai.widgets.view.AvatarView;

import java.util.List;

/**
 * 帮P列表
 *
 * @author: xiaoluo
 * @date: 2017-04-21 15:54
 */
public class PsListAdapter extends BaseAdapter<MissionData> {
    private Context mContext;
    private List<MissionData> mList;

    public static final int PS_TYPE_INPROGRESS = 110;
    public static final int PS_TYPE_REPLY_NOW = 120;
    public static final int PS_TYPE_NORMAL = 130;

    public PsListAdapter(Context context, List<MissionData> list) {
        super(list);
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_ps_list;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        ImageView psImage = holder.getView(R.id.ps_image);
        AvatarView psAvatar = holder.getView(R.id.ps_avatar);
        TextView psNickname = holder.getView(R.id.ps_nickname);
        TextView psDesc = holder.getView(R.id.ps_desc);
        TextView psTime = holder.getView(R.id.ps_time);

        final MissionData item = mList.get(position);
        if (item.getAsk_post() != null) {
            psTime.setText(item.getTpTime());
            psDesc.setText(item.getAsk_post().getDesc());
            psNickname.setText(item.getAsk_post().getUser().getNickname());
            ImageLoadUtil.getInstance().loadAvatar(item.getAsk_post().getUser().getAvatar(), psAvatar);
            psAvatar.setUid(item.getAsk_post().getUser().getId(), false);
            if (item.getAsk_post().getMedias() != null && item.getAsk_post().getMedias().size() != 0) {
                ImageLoadUtil.getInstance().loadImage(item.getAsk_post().getMedias().get(0).getPathname(),
                        psImage, ImageLoadUtil.LoadOption.LOAD_MEDIUM);
            }
        }
    }
}
